
import { deepCopy } from "../deepCopy";
import { SHOPPINGCAR_INIT, SHOPPINGCAR_UPDATE, TOTAL_UPDATE } from "../actionCreators/actionTypes";

export let shopReducer = (state = {
    user: '',
    list: [],
    allChecked: false,
    selectCount: 0,
    total: 0
}, action) => {
    let newState = deepCopy(state);
    switch (action.type) {
        case SHOPPINGCAR_INIT:
            newState.list = action.list;
            newState.user = action.user;
            return newState;
        case SHOPPINGCAR_UPDATE:
            newState.list = action.list == undefined ? newState.list : action.list;
            newState.allChecked = action.allChecked == undefined ? newState.allChecked : action.allChecked;
            newState.selectCount = action.selectCount == undefined ? newState.selectCount : action.selectCount;
            newState.total = action.total == undefined ? newState.total : action.total;
            return newState;
        default:
            return state;
    }
}